#ifndef VIEW_H
#define VIEW_H

#include "model.h"
#include "sigslot.h"
#include <iostream>

/// View
class View : public sigslot::has_slots<>
{
public:
    View::View(Model& m) : m_model(m)
    {
        m_model.Refreshed.connect(this, &View::Refresh);
    }
    
    virtual ~View()
    {
        m_model.Refreshed.disconnect(this); // not really needed
    }
    
    /// slots
    virtual void Refresh(bool extended = true) = 0;

protected:
    Model& m_model;
};

/// Text view
class TextView : public View
{
public:
    TextView(Model& doc) : View(doc) {}

    virtual void Refresh(bool extended) 
    {
        std::cout << "TextView: " << m_model.GetText() << std::endl;
    }
};

/// Hexadecimal view
class HexView : public View
{
public:
    HexView(Model& doc) : View(doc) {}

    virtual void Refresh(bool extended)
    {
        const std::string& s = m_model.GetText();

        std::cout << "HexView:";

        for (std::string::const_iterator it = s.begin(); it != s.end(); ++it)
        {
            std::cout << ' ' << std::hex << static_cast<int>(*it);
        }

        std::cout << std::endl;
    }
};


#endif // VIEW_H
